package study.source.common.resolver;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.view.AbstractView;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.LongSerializationPolicy;

public class JSONView extends AbstractView {

	@SuppressWarnings("unchecked")
	@Override
	protected void renderMergedOutputModel(Map model,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		if (null == model) {
			throw new IOException();
		}
		response.setContentType("text/html; charset=UTF-8");
		PrintWriter out = response.getWriter();
		
		Object value = model.get("value");
		
		
		Gson gson = new GsonBuilder().serializeNulls().setLongSerializationPolicy(LongSerializationPolicy.STRING).create();
		out.println(gson.toJson(value));
		out.flush();
	}

}
